import {Component} from "react";
import {TableHead} from "./tablehead";
import {TableBody} from "./tablebody";

export default class Table extends Component {
    constructor(props) {
        super(props);
        const {tableData,tableHead} = props;
        this.state = {
            tableData: tableData,
            tableHead: tableHead,
        };
    }
    removeRow(index) {
        if (window.confirm('确定删除数据？')) {
            const {tableData} = this.state;
            this.setState({
                tableData: tableData.filter((x,i) => i !== index)
            })
        }
    }
    render() {
        return (
            <table>
                <TableHead tableHead={this.state.tableHead}/>
                <TableBody
                    tableData={this.state.tableData}
                    removeRow={(index)=>{this.removeRow(index)}}
                />
            </table>
        );
    }
}